﻿Imports System.Net

Public Class BrowserForm
    Public Sub Navigate(ByVal url As Uri)
        WebBrowser1.Navigate(url)
    End Sub

    Private Sub WebBrowser1_Navigated(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles WebBrowser1.Navigated
        Dim authCode = System.Web.HttpUtility.ParseQueryString(e.Url.Query)("code")
        Dim errorMessage = System.Web.HttpUtility.ParseQueryString(e.Url.Query)("error")
        If Not String.IsNullOrEmpty(authCode) OrElse Not String.IsNullOrEmpty(errorMessage) Then
            Me.Close()
        End If
    End Sub
End Class